package controle;

import java.rmi.RemoteException;
import java.sql.SQLException;

import javax.xml.soap.Name;

import org.apache.kandula.coordinator.TimedOutException;
import org.apache.kandula.coordinator.ba.participant.ParticipantCancelResult;
import org.apache.kandula.coordinator.ba.participant.ParticipantCloseResult;
import org.apache.kandula.coordinator.ba.participant.ParticipantCompensateResult;

import dominio.FornecedorA;
import dominio.IFornecedorA;

import br.com.pedido.www.FornecedorAPrecoServicoRequest;
import br.com.pedido.www.FornecedorARequisicaoServicoRequest;


import infra.bean.RequisicaoDeCompraBean;





public class FornecedorAServicoParticipante extends org.apache.kandula.coordinator.ba.participant.BAwPCParticipant {
   

	public FornecedorAServicoParticipante(FornecedorAServico service, FornecedorAPrecoServicoRequest request) throws RemoteException {

		super(new org.apache.kandula.coordinator.CoordinationContext(request.getTransactionalContext().getCoordinationContext()), request.getCompensationOrder());
	
	}

	public FornecedorAServicoParticipante(FornecedorAServico service, FornecedorARequisicaoServicoRequest request) throws RemoteException {

		super(new org.apache.kandula.coordinator.CoordinationContext(request.getTransactionalContext().getCoordinationContext()), request.getCompensationOrder());
	
	}
	
	public double verificarPrecoMaterial(String descricao) throws SQLException  {
	   
	    IFornecedorA fornecedorA = new FornecedorA();
	    double preco = fornecedorA.obterPrecoMaterial(descricao);
	    tellCompleted();
	    
	    return preco;
	}
	
	
	public int efetuarRequisicaoDeCompra(RequisicaoDeCompraBean requisicaoDeCompra) throws SQLException  {
		   
	   tellCompleted();
	   return 1;
	}
  
  



@Override
public void onFault(Name arg0) {
	// TODO Auto-generated method stub
	
}



@Override
public void timeout() throws TimedOutException {
	// TODO Auto-generated method stub
	
}


@Override
protected ParticipantCancelResult onCancel() {
	// TODO Auto-generated method stub
	return ParticipantCancelResult.CANCELED;
}


@Override
protected ParticipantCloseResult onClose() {
	// TODO Auto-generated method stub
	return ParticipantCloseResult.CLOSED;
}


@Override
protected ParticipantCompensateResult onCompensate() {
	// TODO Auto-generated method stub
	try {  
		   Thread.sleep(100000);  
		} catch (Exception e) {  
		   e.printStackTrace();  
		}  
	return ParticipantCompensateResult.COMPENSATED;
}


@Override
protected void onFinish() {
	// TODO Auto-generated method stub
	System.out.println("Complete part " + this.myID + " estado: " + this.getState() );	
}




}
